package action;

import Impl.adminDaoImpl;
import dao.adminDao;
import entity.Admin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "SearchAdmin")
public class SearchAdmin extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("----------正在执行SearchAdmin-----------");
        String method = request.getParameter("method");
        adminDaoImpl adminDao=new adminDaoImpl();
        if (method!=null && method.equals("search")){
            System.out.println("正在查找用户");
            String condition = request.getParameter("condition");
            System.out.println(condition);
            List<Admin> adminList =adminDao.findAdminByCondition(condition);
            int allcount=adminList.size();
            request.setAttribute("adminList",adminList);
            request.setAttribute("page", "no");
            request.setAttribute("allcount",allcount);
            request.getRequestDispatcher("/admin-list.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
